package com.agua.enturno.vista.paginas.adm.agendas.horarios;

import com.agua.enturno.servicios.AgendaService;
import com.agua.enturno.vista.dto.AgendaDTO;
import com.agua.enturno.vista.modelos.IntervaloDeHorariosModel;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxLink;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

public class AdministracionDeHorariosPanel extends Panel {

	private static final long serialVersionUID = 1L;

	@SpringBean
	private AgendaService agendaService;
	private IntervaloDeHorariosModel horariosModel;
	private TablaAdministracionDeHorarios tablaAdmHorarios;
	
	private WebMarkupContainer diaPill;
	private WebMarkupContainer semanaPill;
	private WebMarkupContainer mesPill;
	
	
	public AdministracionDeHorariosPanel(String id, IModel<AgendaDTO> model) {
		super(id, model);
		this.setOutputMarkupId(true);
		this.horariosModel = new IntervaloDeHorariosModel(model);
		
		AjaxLink<String> diaLink = new AjaxLink<String>("dia-link") {
			private static final long serialVersionUID = 1L;

			@Override
			public void onClick(AjaxRequestTarget target) {
				horariosModel.setToCurrentDay();
				activeDiaPill();
				target.add(AdministracionDeHorariosPanel.this);
			}
			
		};
		diaPill = new WebMarkupContainer("dia-pill");
		diaPill.add(diaLink);
		add(diaPill);
		
		AjaxLink<String> semanaLink = new AjaxLink<String>("semana-link") {
			private static final long serialVersionUID = 1L;

			@Override
			public void onClick(AjaxRequestTarget target) {
				horariosModel.setToCurrentWeek();
				activeSemanaPill();
				target.add(AdministracionDeHorariosPanel.this);
			}
			
		};
		semanaPill = new WebMarkupContainer("semana-pill");
		semanaPill.add(semanaLink);
		add(semanaPill);
		
		AjaxLink<String> mesLink = new AjaxLink<String>("mes-link") {
			private static final long serialVersionUID = 1L;

			@Override
			public void onClick(AjaxRequestTarget target) {
				horariosModel.setToCurrentMonth();
				activeMesPill();
				target.add(AdministracionDeHorariosPanel.this);
			}
			
		};
		mesPill = new WebMarkupContainer("mes-pill");
		mesPill.add(mesLink);
		add(mesPill);
		
		tablaAdmHorarios = new TablaAdministracionDeHorarios("tabla-adm-horarios", horariosModel);
		add(tablaAdmHorarios);
	}
	
	private void activeDiaPill() {
		diaPill.add(AttributeModifier.replace("class", "active"));
		semanaPill.add(AttributeModifier.remove("class"));
		mesPill.add(AttributeModifier.remove("class"));
	}
	
	private void activeSemanaPill() {
		diaPill.add(AttributeModifier.remove("class"));
		semanaPill.add(AttributeModifier.replace("class", "active"));
		mesPill.add(AttributeModifier.remove("class"));
	}
	
	private void activeMesPill() {
		diaPill.add(AttributeModifier.remove("class"));
		semanaPill.add(AttributeModifier.remove("class"));
		mesPill.add(AttributeModifier.replace("class", "active"));
	}

}
